package com.shuqing.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import
        org.springframework.context.annotation.ComponentScan;
import
        org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import
        org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
@Configuration
//将MyBatisConfig和JdbcConfig类交给Spring管理
@Import({MyBatisConfig.class, JdbcConfig.class})
//等同于<context:component-scan base-package="com.shuqing.service">
@ComponentScan(value = "com.shuqing.service")
//开启事务注解功能，等同于于<tx:annotation-driven transaction-manager="transactionManager" />
@EnableTransactionManagement
public class SpringConfig {
    /**
     * 等同于<bean id="transactionManager"
     class="org.springframework.jdbc.datasource.DataSourceTran
     sactionManager">
     * @param dataSource
     * @return
     */
    @Bean("transactionManager")
    public DataSourceTransactionManager
    getDataSourceTxManager(@Autowired DataSource dataSource)
    {
        DataSourceTransactionManager dtm = new
                DataSourceTransactionManager();
        dtm.setDataSource(dataSource);
        return dtm;
    }
}
